/* check_roboboca.c -- arquivo de testes da biblioteca roboboca
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogofsr@grad.icmc.usp.br>
 *                     Bruno Ribeiro de Oliveira
 *                     Arineiza Cristina Pinheiro
 *                     Tomas Grover
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <stdlib.h>
#include <math.h>
#include <check.h>

#include "roboboca.h"
#include "xmalloc.h"

/* Globais para teste */
roboboca_t * box;
roboboca_robot_t * robot1;
roboboca_robot_t * robot2;
roboboca_robot_t * robot3;

void
setup (void)
{
}

void
teardown (void)
{
}

START_TEST( test_roboboca_laser_to_global_rad )
{
    printf("%f\n",roboboca_laser_to_global_rad( 0, -M_PI_2 ));
    fail_unless( roboboca_laser_to_global_rad( 0, -M_PI_2 ) == -M_PI_2 );
    fail_unless( roboboca_laser_to_global_rad( M_PI_4, -M_PI_2 ) == -M_PI_4 );
    fail_unless( roboboca_laser_to_global_rad( M_PI_2, -M_PI_2 ) == 0 );
    fail_unless( roboboca_laser_to_global_rad( M_PI_2+M_PI_4, -M_PI_2 ) == M_PI_4 );
}
END_TEST

START_TEST( test_roboboca_AvoidObstacle )
{
    double xdelta = 1;
    double ydelta = 2;
    roboboca_AvoidObstacle( 0.5,
			    0,
			    &xdelta,
			    &ydelta );
    if( ydelta != 0 )
	fail();
}
END_TEST

START_TEST( test_roboboca_get_nearest_blob )
{
    roboboca_t * box = NULL;
    roboboca_robot_t * robot = NULL;
    roboboca_robot_t * robot2 = NULL;

    box = roboboca_new(3);
    robot = roboboca_robot_new(	-5,
				-5,
				"localhost",
				6665);
    roboboca_append_robot( box,
			   robot );
    robot2 = roboboca_robot_new(	0,
				0,
				"localhost",
				6666);
    roboboca_append_robot( box,
			   robot2 );
    robot = roboboca_robot_new(	10,
				-5,
				"localhost",
				6667);
    roboboca_append_robot( box,
			   robot );
    
    roboboca_mark_blob( box,
			2,
			2 );
    roboboca_mark_blob( box,
			-2,
			2 );
    roboboca_mark_blob( box,
			-2,
			-2 );
    roboboca_mark_blob( box,
			2,
			-2 );
    roboboca_mark_blob( box,
			11,
			-5 );
    fail_unless( roboboca_get_nearest_blob( box, robot ) == 4 );
    
}
END_TEST

Suite *
roboboca_suite( void )
{
    Suite *s = suite_create( "Roboboca" );
	
    /* Core Test */
    TCase *tc_core = tcase_create( "Core" );
    tcase_add_checked_fixture (tc_core, setup, teardown);
    tcase_add_test( tc_core, test_roboboca_laser_to_global_rad);
    tcase_add_test( tc_core, test_roboboca_AvoidObstacle);
    tcase_add_test( tc_core, test_roboboca_get_nearest_blob);
    suite_add_tcase( s, tc_core );
	
    return s;
}

int
main( void )
{
    int number_failed;
    Suite *s = roboboca_suite ();
    SRunner *sr = srunner_create (s);
    srunner_run_all (sr, CK_NORMAL);
    number_failed = srunner_ntests_failed (sr);
    srunner_free (sr);
    
    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

/*
;;; Local Variables: ***
;;; compile-command: "make check" ***
;;; End: ***
*/
